import { Result } from "../types/result";
import { User } from "../types/user";
import { GetAccessPages } from "../api/module/user";

// let user: User = {
//   'userId': '1992',
//   'username': 'admin',
// }

const menus = [
  {
    id: "/workspace",
    icon: "layui-icon-tabs",
    title: "项目",
    children: [
      {
        id: "/workspace/workbench",
        icon: "layui-icon-rate-half",
        title: "试验检测"
      },
      {
        id: "/workspace/console",
        icon: "layui-icon-username",
        title: "按人统计"
      },
      {
        id: "/workspace/analysis",
        icon: "layui-icon-survey",
        title: "按项目统计"
      }
    ]
  },
  {
    id: "/system",
    icon: "layui-icon-set",
    title: "系统管理",
    children: [
      {
        id: "/system/user",
        icon: "layui-icon-username",
        title: "账号管理",
      },
      {
        id: "/system/role",
        icon: "layui-icon-auz",
        title: "权限管理",
      },
      {
        id: "/system/equipment",
        icon: "layui-icon-engine",
        title: "设备管理",
      },
    ]
  },
]

const getInfo = async (req: any, res: any) => {
  let item = JSON.parse(req.body);
  let token = item ? item.token : null;

  
  let result: Result = {
    code: 200,
    msg: "操作成功",
    data: 'user',
    success: true
  }
  if (item || token) {
    result.code = 99998;
    result.msg = "请重新登录";
    result.success = false;
  }
  return result;
}

const getPermission = (req: any, res: any) => {
  let item = JSON.parse(req.body);
  let token = item ? item.token : null;
  let result: Result = {
    code: 200,
    msg: "操作成功",
    data: ['sys:user:add', 'sys:user:edit', 'sys:user:delete', 'sys:user:import', 'sys:user:export'],
    success: true
  }
  if (item || token) {
    result.code = 99998;
    result.msg = "请重新登录";
    result.success = false;
  }
  return result;
}

const getMenu = async (req: any, res: any) => {
  let item = JSON.parse(req.body);
  let token = item ? item.token : null;
    const items: any = await GetAccessPages({
    pageIndex: 1,
    pagePerCount: 100,
    condition: '',
  })
  let result: Result = {
    code: 200,
    msg: "操作成功",
    data: menus,
    success: true
  }
  if (item || token) {
    result.code = 99998;
    result.msg = "请重新登录";
    result.success = false;
  }
  return result;
}

const getLogin = (req: any, res: any) => {
  let item = JSON.parse(req.body);
  let account = item.account;
  let password = item.password;
  if (account === 'admin' && password === '123456') {
    return {
      'code': 200,
      'msg': '登陆成功',
      'data': {
        'userId': '35002',
        'token': 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoiYWRtaW4iLCJvcmdDb2RlIjoiMzUwMDAiLCJkZXB0Q29kZSI6IjM1MDAwIiwiYXVkIjoiYWRtaW4iLCJpc3MiOiJhZG1pbiIsImV4cCI6MTU5MzUzNTU5OH0.0pJAojRtT5lx6PS2gH_Q9BmBxeNlgBL37ABX22HyDlebbr66cCjVYZ0v0zbLO_9241FX9-FZpCkEqE98MQOyWw',
      }
    }
  } else {
    return {
      'code': 500,
      'msg': '登陆失败,账号密码不正确'
    }
  }
}

const getUpload = (req: any, res: any) => {
  return {
    'code': 200,
    'msg': '上传成功',
    'success': true
  }
}

export default {
  getInfo, getMenu, getLogin, getPermission, getUpload
}